/*
 * @Date: 2022-12-21 12:52:06
 * @LastEditTime: 2023-09-22 15:09:13
 * @FilePath: /wkw/src/common/ts/init.ts
 * 介绍:项目初始化
 */
import type { ConfigProviderThemeVars } from "vant";
import { setDialogDefaultOptions } from "vant";
import { unitPx } from "@@/utils/tools/css";
import { _require } from "@@/utils/tools";

function resetRem() {
  const htmlDom = document.documentElement;
  if (innerWidth < innerHeight * 1.5)
    return (htmlDom.style.fontSize = unitPx(innerWidth / 750));
  htmlDom.style.fontSize = unitPx(0.5);
}

export function eventResetRem() {
  resetRem();
  return window.addEventListener("resize", resetRem);
}
/**vant全局配置 */
export const vantThemeVars: ConfigProviderThemeVars = {};
/**修改Diallog默认配置 */
setDialogDefaultOptions({
  teleport: "body",
  className: "bevel",
  showCancelButton: true,
});

export function preload() {
  const images: string[] = [];
  const backgrounds: string[] = ["src/assets/images/bg/bg1.png"];

  backgrounds.forEach((v) => {
    const appendDiv = document.createElement("div");
    appendDiv.style.opacity = "0";
    appendDiv.style.position = "absolute";
    appendDiv.style.left = "-99999px";
    appendDiv.style.top = "-99999px";
    document.body.append(appendDiv);
    appendDiv.style.backgroundImage = `url(${_require(v)})`;
    setTimeout(() => appendDiv.remove());
  });
  images.forEach((v) => {
    new Image().src = _require(v);
  });
}
